﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using AspNetCs.Common;
using AspNetCs.Model;
using AspNetCs.Bll;
using System.Text;
using AspNetCs.Enumerations.Channel_Enum;
public partial class Skins_cemetery_Default : BasePage
{
    #region 研究


    //public static Regex allDataModuleRegex = new Regex(@"(?<AllDataModule>\<!--netsoftok:(?<DataModuleName>\w+)\>(?<DataModuleContent>.*?)\<\/netsoftok--\>)", RegexOptions.Multiline | RegexOptions.IgnoreCase | RegexOptions.Compiled);


    //foreach (Match m in allDataModuleRegex.Matches(strBuilder.ToString()))
    //{

    //  string  AllDataModuleContent = m.Groups["AllDataModule"].Value;//系统模块符体赋值
    //  string DataModuleContent = m.Groups["DataModuleContent"].Value;//模块代码内容体赋值
    //  string DataModuleNamedd = m.Groups["DataModuleName"].Value;


    //  Response.Write(DataModuleNamedd);

    //}
    //Response.End();

    //Regex regex = new Regex("<img .*src=(\"|')?(\\S*)(\"|')");
    //foreach (Match m in regex.Matches(strBuilder.ToString()))
    //{
    //    string tmp = configInfo.InstallDir + "Skins/cemetery/default/" + m.Groups[2].Value;

    //    Response.Write("网页图片:" + m.Groups[2].Value + "<br>");
    //    strBuilder.Replace(m.Groups[2].Value, tmp);
    //}

    #endregion

    protected int id = 0;
    protected Cemetery_Model mdel = new Cemetery_Model();

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Buffer = true;
        Response.ExpiresAbsolute = System.DateTime.Now.AddSeconds(-1);
        Response.Expires = 0;
        Response.CacheControl = "no-cache";
        Response.AddHeader("Pragma", "No-Cache");


        if (Request["id"] != null)
        {
            id = StringHelper.isNumber_int(Request["id"].ToString());
        }
        mdel = Cemetery_Bll.CreateNew.GetModel(id);
        if (mdel.Id <= 0)
        {
            ShowMsgBack("错误提示：当前馆号不存在!");
            Response.End();
        }

        if (Base_GetLoginInfo.GetUserID <= 0)
        {

            ResultStr(configInfo.InstallDir + "users/Login.Aspx?ReUrl=" + Server.UrlEncode(configInfo.InstallDir + "skins/cemetery/default.aspx?id=" + id), "对不起，请您先登录再进行此项操作!");
            Response.End();
        }

        if (mdel.CreateId != Base_GetLoginInfo.GetUserID)
        {
            ShowMsgBack("对不起，当前馆号不属于您，您无权管理!");
            Response.End();
        }

        if (mdel.TempleId <= 0)
        {
            ShowMsgBack("当前陵园未设置模板，请返回重新设置!");
            Response.End();
        }

        // StringHelper.copyfolder(Server.MapPath(configInfo.InstallDir + "Skins/cemetery/default/"), Server.MapPath(configInfo.InstallDir + "g/"));
        //StringHelper.CopyDir(Server.MapPath(configInfo.InstallDir + "Skins/cemetery/default/"), Server.MapPath(configInfo.InstallDir + "g/"));

        //Response.End();

        //System.IO.StreamReader str = new System.IO.StreamReader(Server.MapPath(configInfo.InstallDir + "Skins/cemetery/default/index.html"));
        //string html = null;

        //while ((html = str.ReadLine()) != null)
        //{
        //    strBuilder.AppendLine(html);
        //}
        //str.Close();



        StringBuilder newstr = new StringBuilder();
        newstr.AppendLine("<script>");
        newstr.AppendLine("<!--");
        newstr.AppendLine("var Numid='" + mdel.Numid + "';");//陵园馆号
        newstr.AppendLine("var id='" + mdel.Id + "';");//陵园ID
        newstr.AppendLine("var UserID='" + mdel.CreateId + "';");//陵园名称
        newstr.AppendLine("var Pid='" + mdel.Province + "';");//省份
        newstr.AppendLine("var CityID='" + mdel.City + "';");//城市
        newstr.AppendLine("-->");
        newstr.AppendLine("</script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/jquery.js'></script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/jquery.easydrag.js?id=" + id + "&rnd=" + new Random().Next(1000, 9999999) + "'></script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/Cemetery.Aspx'></script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/Cememtery_AddMsg.aspx'></script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/Cemetery_load.aspx?id=" + id + "&rnd=" + new Random().Next(1000, 9999999) + "'></script>");
        newstr.AppendLine("<script src='" + configInfo.InstallDir + "Script/Cememtery_Master.aspx?id=" + id + "&rnd=" + new Random().Next(1000, 9999999) + "'></script>");

        Temple_Model md = TempleBll.CreateNew.GetModel(mdel.TempleId);
        string ServerUrl = configInfo.InstallDir + StringHelper.ReadConfig("TempleSkin") + Channel_Type.cemetery.ToString().ToLower() + "/" + md.TemplePath.ToString() + "/index.html";

        strBuilder = TempleBll.CreateNew.WriteHtml(Server.MapPath(ServerUrl), newstr.ToString());




        GetStringData_lable lbReplace = new GetStringData_lable();

        Response.Write(lbReplace.GetResultStr(strBuilder.ToString(), "Cemetery", Cemetery_Bll.CreateNew.GetDataTable(" id=" + id)));
    }


}